//
//  GNRViewController.m
//  GNRAlertView
//
//  Created by ly918@qq.com on 09/12/2017.
//  Copyright (c) 2017 ly918@qq.com. All rights reserved.
//

#import "GNRViewController.h"
#import <GNRAlertView/GNRAlertView.h>
#import <MessageUI/MFMessageComposeViewController.h>

@interface GNRViewController ()<MFMessageComposeViewControllerDelegate,UIActionSheetDelegate>
- (IBAction)itemAction:(id)sender;

@end

@implementation GNRViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    

	// Do any additional setup after loading the view, typically from a nib.
}

- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result{
    [controller dismissViewControllerAnimated:YES completion:nil];
    if (result == MessageComposeResultCancelled)
    NSLog(@"Message cancelled");
    else if (result == MessageComposeResultSent)
    NSLog(@"Message sent");
    else
    NSLog(@"Message failed");
}

- (void)showSMS{
    MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
    if([MFMessageComposeViewController canSendText])
    {
        controller.body = @"AAAAAA";
        controller.recipients = @[@"13333820378"];
        controller.messageComposeDelegate = self;
        [self presentViewController:controller animated:YES completion:^{
            GNRAlertView * alert = [GNRAlertView alertWithTitle:@"asd" msg:@"asd" cancelBtnTip:@"取消" otherBtnTips:[self btnTipsWithCount:3] actionCallback:^(NSInteger buttonIndex) {
                [self.navigationController pushViewController:[UIViewController new] animated:YES];
            }];
            [alert show];
        }];
        
    }
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell * cell = [tableView cellForRowAtIndexPath:indexPath];
    [self showAlertViewWithTitle:[self titleWithCell:cell] index:indexPath.row];
}

int se = 0;
- (void)alerts{
    se = 0;
    NSTimer * timer = [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(timerAction:) userInfo:nil repeats:YES];
    [timer setFireDate:[NSDate date]];
}

- (void)timerAction:(NSTimer *)sender{
    se++;
    if (se<12) {
        [self showAlertViewWithTitle:[NSString stringWithFormat:@"title %d",se] index:se];
    }else{
        [sender setFireDate:[NSDate distantFuture]];
    }
}

- (void)showAlertViewWithTitle:(NSString*)title index:(NSInteger )index{
    __weak GNRAlertView  * alert = nil;
    switch (index) {
            case 0:
        {
            alert = [GNRAlertView alertWithTitle:title msg:@"取消取消取消取消取消取消取消,取消取消取消取消取消取消取消,取消取消取消取消取消取消取消,取消取消取消取消取消取消取消,取消取消取消取消取消取消取消,取消取消取消取消取消取消取消,取消取消取消取消取消取消取消,取消取消取消取消取消取消取消,取消取消取消取消取消取消取消,取消取消取消取消取消取消取消,取消取消取消取消取消取消取消,取消取消取消取消取消取消取消,取消取消取消取消取消取消取消,取消取消取消取消取消取消取消,取消取消取消取消取消取消取消,取消取消取消取消取消取消取消,取消取消取消取消取消取消取消,取消取消取消取消取消取消取消,取消取消取消取消取消取消取消,取消取消取消取消取消取消取消,取消取消取消取消取消取消取消,取消取消取消取消取消取消取消,取消取消取消取消取消取消取消,取消取消取消取消取消取消取消,取消取消取消取消取消取消取消,取消取消取消取消取消取消取消,取消取消取消取消取消取消取消,取消取消取消取消取消取消取消,取消取消取消取消取消取消取消,取消取消取消取消取消取消取消,取消取消取消取消取消取消取消,取消取消取消取消取消取消取消。" cancelBtnTip:@"取消" otherBtnTips:[self btnTipsWithCount:1] actionCallback:^(NSInteger buttonIndex) {
                NSLog(@"%d", (int)buttonIndex);
                if (buttonIndex==1) {

                    [self showSMS];
                }
            }];
        }
            break;
            case 1:
        {
            alert = [GNRAlertView alertWithTitle:title msg:title cancelBtnTip:@"取消" otherBtnTips:[self btnTipsWithCount:3] actionCallback:^(NSInteger buttonIndex) {
                NSLog(@"%d",(int) buttonIndex);
            }];
        }
            break;
            case 2:
        {
            alert = [GNRAlertView alertWithTitle:title alertFieldStyle:GNRAlertFieldStyleTextInput cancelBtnTip:@"取消" otherBtnTips:[self btnTipsWithCount:2] textFieldActionCallback:^(NSInteger buttonIndex, NSArray *texts ,GNRAlertView * alertView) {
                NSLog(@"%d %@",(int) buttonIndex,texts);
                if ([[texts firstObject] length]) {
                    [alertView dismiss];
                }
            }];
            alert.placeHolder = @"请输入姓名";
        }
            break;
            case 3:
        {
            alert = [GNRAlertView alertWithTitle:title alertFieldStyle:GNRAlertFieldStyleMoneyInput cancelBtnTip:@"取消" otherBtnTips:[self btnTipsWithCount:2] textFieldActionCallback:^(NSInteger buttonIndex, NSArray *texts,GNRAlertView * alertView) {
                NSLog(@"%d %@",(int) buttonIndex,texts);
            }];
            alert.upLimitMoney = 20;
            alert.inputUpLimitMoneyBlock = ^{
                NSLog(@"输入金额超过最大金额");
            };
        }
            break;
            case 4:
        {
            alert = [GNRAlertView alertWithTitle:title alertFieldStyle:GNRAlertFieldStyleLoginInput cancelBtnTip:@"取消" otherBtnTips:[self btnTipsWithCount:2] textFieldActionCallback:^(NSInteger buttonIndex, NSArray *texts,GNRAlertView * alertView) {
                NSLog(@"%d %@",(int) buttonIndex,texts);
            }];
        }
            break;
            case 5:
        {
            alert = [GNRAlertView alertWithTitle:title alertFieldStyle:GNRAlertFieldStyleTextInput cancelBtnTip:@"取消" otherBtnTips:[self btnTipsWithCount:2] textFieldActionCallback:^(NSInteger buttonIndex, NSArray *texts,GNRAlertView * alertView) {
                NSLog(@"%d %@",(int) buttonIndex,texts);
                if ([[texts firstObject] length]) {
                    [alertView dismiss];
                    GNRAlertView * alert1 = [GNRAlertView alertWithTitle:title alertFieldStyle:GNRAlertFieldStyleLongTextInput cancelBtnTip:@"取消" otherBtnTips:[self btnTipsWithCount:2] textFieldActionCallback:^(NSInteger buttonIndex, NSArray *texts,GNRAlertView * alertView1) {
                        NSLog(@"%d %@",(int) buttonIndex,texts);
                        
                    }];
                    alert1.placeHolder = @"我是默认文字";
                    [alert1 show];
                }
            }];
        }
            break;
            case 6:
        {
            alert = [GNRAlertView alertWithTitle:title msg:title cancelBtnTip:@"取消" otherBtnTip:@"确定" actionCallback:^(NSInteger buttonIndex) {
                NSLog(@"%d",(int)buttonIndex);
            } timeDoneCallback:^(GNRAlertView *alertView) {
                alertView.title = @"ASDADSSADasdfasdfasdfasdfadsfASDASD";
                alertView.msg = @"MSadsdasdasdasdas dasdffadsfasdfasdfasdfasdfasdfasdfasdf";
                [alertView updateCancelBtnTip:@"取消1"];
                [alertView updateOtherBtnTips:@[@"ASD1",@"ASD2",@"SD2"]];
            }];
            alert.countDownMaxTime = 5;
            
        }
            break;
            case 7:
        {
            alert = [GNRAlertView alertWithTitle:title msg:title cancelBtnTip:@"取消" otherBtnTip:@"确定" actionCallback:^(NSInteger buttonIndex) {
                NSLog(@"%d",(int)buttonIndex);
            } timeDoneCallback:^(GNRAlertView *alertView) {
                [alertView dismiss];
            }];
            alert.countDownMaxTime = 5;
        }
            break;
            case 8:
        {
            alert = [GNRAlertView alertWithTitle:title linkTip:@"点击查看" cancelBtnTip:@"我知道了" otherBtnTips:@[@"确定"] actionCallback:^(NSInteger buttonIndex) {
                NSLog(@"%d", (int)buttonIndex);
            } linkActionBlock:^{
                NSLog(@"Link Action");
            }];
            alert.headerBgImage=[UIImage imageNamed:@"alert_bg_orange"];
        }
            break;
            case 9:
        {
            alert = [GNRAlertView alertWithTitle:title linkTip:@"点击查看" cancelBtnTip:@"我知道了" otherBtnTips:@[@"确定"] actionCallback:^(NSInteger buttonIndex) {
                NSLog(@"%d", (int)buttonIndex);
            } linkActionBlock:^{
                NSLog(@"Link Action");
            }];
            alert.alertStyle = GNRAlertStyleDefault;
        }
            break;
            case 10:
        {
            [GNRAlertView alertWithTitle:@"" msg:@"请检查网络设置"];
        }
            break;
            case 11:
        {
            alert = [GNRAlertView alertWithTitle:@"信用分说明" msg:@"1.跑男男男男男啊实打实打实大大所大多啊实打实大大所大多啊实大大所大多啊实打实大师大师多\n2.跑男男男男男啊实打打实大大所大多啊实实大大所大多啊实打实大师大师多\n3.跑男男打实大大所大多啊实男男男啊实打实大大所大多啊实打实大师大师多\n" cancelBtnTip:@"取消" otherBtnTips:[self btnTipsWithCount:3] actionCallback:^(NSInteger buttonIndex) {
                NSLog(@"%d",(int) buttonIndex);
            }];
            alert.alertStyle = GNRAlertStyleBig;
            alert.headerBgImage=[UIImage imageNamed:@"alert_bg_blue"];
        }
            break;
            case 12:
        {
            alert = [GNRAlertView alertWithTitle:@"信用分说明" msg:@"1.跑男男男{男男啊实打实打实大}大所大多啊实打实大大所大多啊实大大所大多啊实打实大师大师多\n2.跑男男男男男啊实打打实大大所大多啊实实大大所大多啊实打实大师大师多\n3.跑男男打实大大所大多啊实男男男啊实打实大大所大多啊实打实大师大师多" cancelBtnTip:nil otherBtnTips:[self btnTipsWithCount:1] actionCallback:^(NSInteger buttonIndex) {
                NSLog(@"%d",(int) buttonIndex);
            }];
            alert.alertStyle = GNRAlertStyleNoHeader;
            alert.msgLabelAlignment = NSTextAlignmentLeft;
        }
            break;
            case 13:
        {
            alert = [GNRAlertView alertWithTitle:@"跑男男男男男啊实打实打实大大所" msg:@"阿斯达撒啊斯达撒啊斯达撒啊斯达撒啊斯达撒啊斯达撒啊斯达撒啊斯达撒啊斯达撒{啊斯达撒啊斯达撒啊斯达撒}啊斯达撒啊实打{实大师}大师多" cancelBtnTip:@"取消" otherBtnTips:[self btnTipsWithCount:1] actionCallback:^(NSInteger buttonIndex) {
                NSLog(@"%d",(int) buttonIndex);
            }];
            
            alert.alertStyle = GNRAlertStyleNoHeader;
        }
            break;
            case 14:
        {
            alert = [GNRAlertView alertWithTitle:@"跑男男男男男{啊实打}实打实大大所" msg:@"阿斯达撒啊实打实大啊实打实大啊实打实大啊实打实大啊实打实大啊实打实大啊实打实大啊实打实大啊实打实大啊实打实大啊实打实大啊实打实大啊实打实大师大师多" cancelBtnTip:@"取消" otherBtnTips:[self btnTipsWithCount:1] actionCallback:^(NSInteger buttonIndex) {
                NSLog(@"%d",(int) buttonIndex);
            }];
            
            alert.alertStyle = GNRAlertStyleNoHeader;
        }
            break;
            case 15:
        {
            alert = [GNRAlertView alertWithTitle:@"跑男男男男男{啊实打}实打实大大所" msg:@"阿斯达撒啊实打实大啊实打实大啊实打实大啊实打实大啊实打实大啊实打实大啊实打实大啊实打实大啊实打实大啊实打实大啊实打实大啊实打实大啊实打实大师大师多" cancelBtnTip:@"取消" otherBtnTips:[self btnTipsWithCount:1] actionCallback:^(NSInteger buttonIndex) {
                NSLog(@"%d",(int) buttonIndex);
            }];
            
            alert.alertStyle = GNRAlertStyleShare;
            alert.headerBgImage = [UIImage imageNamed:@"share"];
        }
            break;
            case 16:
        {
            alert = [GNRAlertView alertWithTitle:@"支付宝" msg:@"支付金额100.0元" cancelBtnTip:@"取消" otherBtnTips:[self btnTipsWithCount:1] actionCallback:^(NSInteger buttonIndex) {
                NSLog(@"%d",(int) buttonIndex);
            }];
            
            alert.iconImage = [UIImage imageNamed:@"alipay_icon"];
        }
            break;
            case 17:
        {
            UIView * view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 300, 100)];
            view.backgroundColor = [UIColor redColor];
            
            alert = [GNRAlertView alertWithTitle:@"" customView:view cancelBtnTip:@"取消" otherBtnTips:nil actionCallback:^(NSInteger buttonIndex) {
                NSLog(@"%d",(int) buttonIndex);
            }];
            
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                alert.title = @"上传失败";
                [alert updateOtherBtnTips:@[@"重新上传"]];
            });
            
        }
            break;
        case 18://测试带标识
        {
            GNRAlertView *alert =[GNRAlertView alertWithTitle:@"Type-1 第一个" msg:nil cancelBtnTip:@"cancel" otherBtnTips:@[@"ok"] actionCallback:^(NSInteger buttonIndex) {
                if (buttonIndex==1) {
                    GNRAlertView *alert2 =[GNRAlertView alertWithTitle:@"Type-3" msg:nil cancelBtnTip:@"cancel" otherBtnTips:@[@"ok"] actionCallback:^(NSInteger buttonIndex) {
                        if (buttonIndex==1) {
                            GNRAlertView *alert3 =[GNRAlertView alertWithTitle:@"Type-None" msg:nil cancelBtnTip:@"cancel" otherBtnTips:@[@"ok"] actionCallback:^(NSInteger buttonIndex) {
                                
                            }];
                            [alert3 show];
                        }
                    }];
                    alert2.identifier = @"Type-2";
                    [alert2 show];
                }
            }];
            alert.identifier = @"Type-1";
            [alert show];
            
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                GNRAlertView *alert1 =[GNRAlertView alertWithTitle:@"Type-33 第二个" msg:nil cancelBtnTip:@"cancel" otherBtnTips:@[@"ok"] actionCallback:^(NSInteger buttonIndex) {
                    if (buttonIndex==1) {
                        GNRAlertView *alert2 =[GNRAlertView alertWithTitle:@"Type-3" msg:nil cancelBtnTip:@"cancel" otherBtnTips:@[@"ok"] actionCallback:^(NSInteger buttonIndex) {
                            if (buttonIndex==1) {
                                GNRAlertView *alert3 =[GNRAlertView alertWithTitle:@"Type-None" msg:nil cancelBtnTip:@"cancel" otherBtnTips:@[@"ok"] actionCallback:^(NSInteger buttonIndex) {
                                    
                                }];
                                [alert3 show];
                            }
                        }];
                        alert2.identifier = @"Type-2";
                        [alert2 show];
                    }
                }];
                alert1.identifier = @"Type-33";
                [alert1 show];
            });
        }
            break;
        case 19:{
//            GNRAlertView *alertNew = [[GNRAlertView alloc]initWithAlertActionType:ACTION_TYPE_MONEY title:@"测试测试测试" des:@"" actions:^(NSInteger index,id content) {
//
//            }];
//            alertNew.warningImageStr = @"alert_warning_icon";
//            alertNew.actionTitleArr = @[@"取消",@"确定"];
//            alertNew.placeHolderContent = @"￥ 请输入金额";
////            alertNew.versionWordStr = @"1.增加IM聊天回复模板功能，和师傅沟通更方便了。\n2.软件性能优化，使用更加流畅了。\n3.修复了用户反馈的bug，使用效果更佳,建议更新指数5颗星。";
//            alertNew.dismissOnTapEnable = NO;
//            alertNew.MAX_NUMBER  = 50;
//            [alertNew showUU_Alert];
//
            
            GNRAlertView *alertView = [[GNRAlertView alloc]initWithAlertActionType:ACTION_TYPE_MONEY title:@"测试测试测试" des:@"" actions:^(NSInteger index,id content) {
                
            }];
            alertView.warningImageStr = @"alert_warning_icon";
            alertView.actionTitleArr = @[@"取消",@"确定"];
            alertView.dismissOnTapEnable = YES;
            alertView.placeHolderContent = @"￥  请输入金额";
//            alertView.versionWordStr = @"1.增加IM聊天回复模板功能，和师傅沟通更方便了。\n2.软件性能优化，使用更加流畅了。\n3.修复了用户反馈的bug，使用效果更佳,建议更新指数5颗星。";
            [alertView showUU_Alert];
        }
            break;
        default:
            break;
    }
    [alert show];
}

- (NSString *)titleWithCell:(UITableViewCell *)cell{
    UILabel * label = [cell viewWithTag:1];
    return label.text;
}

- (NSArray *)btnTipsWithCount:(NSInteger)count{
    NSMutableArray * tips = [NSMutableArray arrayWithCapacity:count];
    for (int i=0; i<count; i++) {
        [tips addObject:[NSString stringWithFormat:@"按钮%d",i+1]];
    }
    return tips;
}

- (IBAction)itemAction:(id)sender {
    UIActionSheet * sheet = [[UIActionSheet alloc]initWithTitle:@"切换风格" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"默认风格",@"大色块风格",@"没有头部风格",@"分享样式",@"商户端风格", nil];
    [sheet showInView:self.view];
}

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (buttonIndex < 5) {
        [GNRAlertManager setDefaultStyle:buttonIndex];
    }
}

@end
